<template>
  <div id="home">
    <Header />
    <div class="conWidth home-box">
      <div class="banner">
        <el-carousel trigger="click" :interval="5000">
          <el-carousel-item v-for="(item, index) in banner" :key="index">
            <img :src="imgHost + item.bannerImg" alt="" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="main j_c_box">
        <article>
          <div
            class="article"
            v-for="(item, index) of articleList"
            :key="index"
          >
            <div class="img">
              <img
                :src="imgHost + item.description_image_path"
                alt=""
                v-if="item.description_image_path"
              />
              <img src="@/assets/img/index/icon1.png" alt="" v-else />
            </div>
            <div class="article_info columnBox j_b_box">
              <div class="content">
                <h2>{{ item.title }}</h2>
                <p v-html="item.content" class="two-hidden"></p>
              </div>
              <div class="user-info centerBox">
                <div class="user">
                  <el-avatar
                    :size="16"
                    :src="'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'"
                  ></el-avatar>
                  <span>admin</span>
                </div>
                <div class="date">
                  <i class="el-icon-date"></i>
                  <span>{{ item.time }}</span>
                </div>
                <div class="see">
                  <i class="el-icon-thumb"></i>
                  <span>2,290次</span>
                </div>
              </div>
            </div>
          </div>
          <!-- 分页器 -->
          <Pagination
            :total="total"
            @pagination="pagination"
            @handleSizeChange="handleSizeChange"
          />
        </article>
        <aside>
          <div class="hot-box">
            <div class="hot-title">
              <h2>热门推荐</h2>
            </div>
            <div class="hot-img" v-if="hotList[0]">
              <img :src="imgHost + hotList[0].description_image_path" alt="" v-if="hotList[0].description_image_path" />
              <img src="@/assets/img/index/icon1.png" alt="" v-else />
            </div>
            <ul class="hot-article">
              <li
                class="one-hidden"
                v-for="(item, index) of hotList"
                :key="index"
              >
                {{ item.title }}
              </li>
            </ul>
          </div>
        </aside>
      </div>
    </div>
    <Footer />
  </div>
</template>
<script>
const Header = () => import("@/components/header/header");
const Footer = () => import("@/components/footer/footer");
const Pagination = () => import('@/components/Pagination');
import { Indicator } from "mint-ui";
export default {
  components: {
    Header,
    Footer,
    Pagination
  },
  data() {
    return {
      articleList: [], // 文章列表
      page: {}, // 文章页数
      queryForm: {
        size: 10,
        current: 1,
      },
      total: 0,
      hotList: [], // 热门文章
      banner: [], // 轮播图
      webPageId: 0,
    };
  },
  created() {
    this.webPageId = this.$route.query;
    console.log(this.$route.query);
    this.getArticle();
    this.getHot();
    this.getBanner();
  },
  methods: {
    // 获取文章列表
    getArticle() {
      Indicator.open();
      this.$http.get("api/article", { params: this.queryForm }).then((res) => {
        Indicator.close();
        this.articleList = res.data.pageList;
        this.page = res.data.page;
        this.total = res.data.page.total;
      });
    },
    // 获取热门文章
    getHot() {
      this.$http
        .get("api/article", { params: { hots: 1, size: 10, current: 1 } })
        .then((res) => {
          this.hotList = res.data.pageList;
        });
    },
    getBanner() {
      this.$http.get("api/banner/getBanner").then((res) => {
        this.banner = res.data;
      });
    },
    // 分页事件
    pagination({ page: current, limit: size }) {
      this.queryForm.current = current
      this.getArticle()
    },
    handleSizeChange({ page: current, limit: size }) {
      this.queryForm.size = size
      this.getArticle()
    },
  },
};
</script>
<style scoped lang="less">
#home {
  background: #f5f5f5;
  width: 100%;
  overflow: hidden;
  .main {
    width: 100%;
  }
  .home-box {
    .banner {
      background: #fff;
      width: 100%;
      height: 420px;
      margin-bottom: 35px;
      /deep/ .el-carousel {
        height: 100%;
        width: 100%;
        .el-carousel__container,
        .el-carousel-item,
        img {
          height: 100% !important;
          width: 100%;
        }
        .el-carousel__item.is-active {
          z-index: 0 !important;
        }
      }
    }
    article {
      width: 72%;
      .article {
        display: flex;
        padding: 20px;
        box-sizing: border-box;
        background: #fff;
        box-shadow: 0 0 5px 5px rgba(0, 0, 0, 0.01);
        margin-bottom: 20px;
        img {
          width: 180px;
          height: 120px;
          margin-right: 20px;
        }
        .article_info {
          align-items: baseline;
          .content {
            font-weight: 500;
            h2 {
              margin-bottom: 10px;
            }
          }
          .user-info {
            & > div {
              margin-right: 10px;
              display: flex;
              align-items: center;
              span {
                margin-left: 5px;
              }
            }
          }
        }
      }
    }
    aside {
      width: 26%;
      padding: 20px;
      box-sizing: border-box;
      background: #fff;
      margin-bottom: 20px;
      .hot-box {
        .hot-title {
          border-bottom: 2px solid #000;
          h2 {
            margin-bottom: 10px;
          }
        }
        .hot-img {
          width: 100%;
          height: 130px;
          margin: 20px 0;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .hot-article {
          li {
            margin: 8px 0;
            padding-left: 8px;
            border-left: 2px solid #cccccc;
            box-sizing: border-box;
            cursor: pointer;
          }
        }
      }
    }
  }
}
</style>